<?php

namespace app\admin\controller;

use app\common\controller\AdminBaseController;

class MenuController extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize();
        $this->server = model('server.menu');
    }

    public function getMenuTreeOp()
    {
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getTree('');

        return $responseData;
    }

    public function saveMenuAddOp()
    {
        $requestData = validateRequestParam('menu', 'saveAdd');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('SAVE_SUCCESS')];
        $responseData['data'] = $this->server->saveAdd($requestData);

        return $responseData;
    }

    public function getMenuRowOp()
    {
        $requestData = validateRequestParam('menu', 'getRow');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getRow($requestData);

        return $responseData;
    }

    public function saveMenuEditOp()
    {
        $requestData = validateRequestParam('menu', 'saveEdit');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('SAVE_SUCCESS')];
        $responseData['data'] = $this->server->saveEdit($requestData);

        return $responseData;
    }

    public function saveMenuDelOp()
    {
        $requestData = validateRequestParam('menu', 'saveEdit');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('DEL_SUCCESS')];
        $responseData['data'] = $this->server->saveDel($requestData);

        return $responseData;
    }

    public function getMenuPowerOp()
    {
        $requestData = validateRequestParam('menu', 'saveEdit');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getPower($requestData);

        return $responseData;
    }

    public function saveMenuPowerOp()
    {
        $requestData = validateRequestParam('menu', 'savePower');
        $responseData['meta'] = ['code' => 1, 'msg' => lang('AUTH_SUCCESS')];
        $responseData['data'] = $this->server->savePower($requestData);

        return $responseData;
    }

    public function getTreeMenuAllOp()
    {
        $data['status'] = 1;
        $responseData['meta'] = ['code' => 1, 'msg' => lang('GET_SUCCESS')];
        $responseData['data'] = $this->server->getTree($data);

        return $responseData;
    }
}
